%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Single particle states in a harmonic potential.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function QA_Movimento_Harmonic

	Constant;
	figure(1);					clf;

	m =87*uA;
	wT=2*pi*100;
	aT=sqrt(hP/m/wT);
	x =[-5:.005:5]*aT;
	V =m/2*wT^2*x.^2;

	N =6;
	for nn=0:N
		E =nn;
		n =1;
		ps=exp(-(x/aT).^2/2).*Hermite(x/aT,nn);
		ps=ps/sqrt(sum(abs(ps.^2)*(x(2)-x(1))));
		ps=abs(ps).^2*1.7e-6 + (nn+1/2);
		subplot(121),fill(x/aT,ps,'b','LineWidth',1.4)
		set(gca,'xLim',[-5 5],'yLim',[0 7],'FontSize',16,'LineWidth',1.4);
		xlabel(['$\displaystyle x/a_{ho}$'],'interpreter','latex','Color','k','FontSize',20)
		ylabel(['$\displaystyle E/\hbar\omega_{ho} ~ ~ , ~ ~ \psi(x)$'],'interpreter','latex','Color','k','FontSize',20);
		hold on;
	end
	subplot(121),plot(x*1e6,V/hP/wT,'r','LineWidth',1.4)
end


function H = Hermite(x,nn)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Hermite-Polynome.

H=0;
if nn/2==floor(nn/2)
  n=nn/2;
  for m=0:n
    H=H+prod(1:2*n  )./prod(1:2*m  ).*(-1).^(n-m)./prod(1:n-m).*(2*x).^(2*m  );
  end
else
  n=(nn-1)/2;
  for m=0:n
    H=H+prod(1:2*n+1)./prod(1:2*m+1).*(-1).^(n-m)./prod(1:n-m).*(2*x).^(2*m+1);
  end
end
end
